package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.dto.BalanceDTO;
import com.tbit.uqbike.object.pojo.dto.BalanceDownloadDTO;
import com.tbit.uqbike.object.pojo.dto.BalancePageDTO;
import com.tbit.uqbike.object.pojo.vo.TotalBalanceVO;
import com.tbit.uqbike.object.pojo.vo.UserBalanceVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.UserBalanceStatService;
import com.tbit.uqbike.webmanager.util.csv.annotations.AsyncDownload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分账管理-用户余额统计
 *
 * @AUTHOR: wei.xing
 * @DATE: 2022-11-22 16:29
 **/
@RequestMapping("/userBalanceStat")
@RestController
public class UserBalanceStatController {

    @Autowired
    UserBalanceStatService balanceStatService;


    /**
     * 查询总统计
     *
     * @param balanceDTO
     * @return
     */
    @GetMapping("/getTotalBalance")
    public Result<TotalBalanceVO> getTotalBalance(@Valid BalanceDTO balanceDTO) {
        TotalBalanceVO totalBalanceVO = balanceStatService.getTotalBalance(balanceDTO);
        return Result.success(totalBalanceVO);
    }


    /**
     * 分页查询用户余额信息
     *
     * @param balancePageDTO
     * @return
     */
    @GetMapping("/getBalancePage")
    public Result<PageResult<UserBalanceVO>> getBalancePage(@Valid BalancePageDTO balancePageDTO) {
        PageResult<UserBalanceVO> pageResult = balanceStatService.getBalancePage(balancePageDTO);
        return Result.success(pageResult);
    }


    /**
     * 账单下载
     *
     * @param downloadDTO
     * @return
     */
    @PostMapping("/download")
    @AsyncDownload(defaultFileName = "用户余额统计")
    public Result download(@RequestBody @Valid BalanceDownloadDTO downloadDTO) {
        String url = balanceStatService.download(downloadDTO);
        return Result.success(url);
    }
}
